"""
@author: jpj
@email: pj.jiang@hzgosun.com
@file: researchConfigTest.py
@time: 2019/7/25 18:31

"""
import unittest
from time import sleep

from common.decorators import log4gs, mkdir_classname
from common.settings import TAG
from pages.researchConfigPage import ResearchConfig


@log4gs
@mkdir_classname(TAG)
class DelayConfigurationTest(unittest.TestCase):
    """研发配置功能测试"""

    @classmethod
    def setUpClass(cls):
        cls.log.info('=' * 30 + '研发配置功能测试' + '=' * 30)
        cls.page = ResearchConfig('/DataManage/ResearchConfig')

    @classmethod
    def tearDownClass(cls):
        cls.log.info('=' * 30 + "结束研发配置功能测试({})".format(__class__.__name__) + '=' * 30)
        cls.page.driver.quit()

    def setUp(self):
        self.log.info('>>>>>开始执行用例：{} {}'.format(self.id(), self.shortDescription()))

    def tearDown(self):
        sleep(3)
        self.log.info('<<<<<结束执行用例：{} {}'.format(self.id(), self.shortDescription()))

    def test_1_system_optimization(self):
        """系统优化警情-配置"""
        num1 = 12
        num2 = 32
        try:
            self.page.start_Time.clear()
            self.page.end_time.clear()
            sleep(1)
            self.page.start_Time.send_keys(num1)
            self.page.end_time.send_keys(num2)
            sleep(1)
            self.page.button[0].click()
            sleep(1)
            self.assertEqual(self.page.success.text, "应用成功")
            sleep(0.1)
            self.log.info("配置{}{}小时提示框：{}".format(num1, num2, self.page.success.text))
            self.log.info("用例{}修改{}-{}小时系统优化警情-配置执行成功".format(self.id(), num1, num2))
        except:
            self.log.error("用例{}修改{}-{}小时系统优化警情-配置执行失败".format(self.id(), num1, num2))

    def test_2_Screening_alert(self):
        """人工筛选警情-配置"""
        num = 1
        try:
            self.page.alarm_interval.clear()
            sleep(1)
            self.page.alarm_interval.send_keys(num)
            sleep(1)
            self.page.button[1].click()
            sleep(1)
            self.assertEqual(self.page.success.text, "应用成功")
            sleep(0.1)
            self.log.info("配置{}小时提示框：{}".format(num, self.page.success.text))
            self.log.info("用例{}修改{}小时人工筛选警情-配置执行成功".format(self.id(), num))
        except:
            self.log.error("用例{}修改{}小时人工筛选警情-配置执行失败".format(self.id(), num))

    def test_3_Deal_timeout(self):
        """警情处理超时-配置"""
        num = 6
        try:
            self.page.overtime.clear()
            sleep(1)
            self.page.overtime.send_keys(num)
            sleep(1)
            self.page.button[2].click()
            sleep(1)
            self.assertEqual(self.page.success.text, "应用成功")
            sleep(0.1)
            self.log.info("配置{}小时提示框：{}".format(num, self.page.success.text))
            self.log.info("用例{}修改{}小时警情处理超时-配置执行成功".format(self.id(), num))
        except:
            self.log.error("用例{}修改{}小时警情处理超时-配置执行失败".format(self.id(), num))


if __name__ == '__main__':
    unittest.main()
